<template>
  <el-container>
    <!-- 头部 -->
    <el-header>
      <img
        style="width: 146px; height: 38px"
        src="../assets/QQ20210331151646.jpg"
      />
      <el-button type="info" @click="logout">退出</el-button>
    </el-header>
    <!-- 页面主题 -->
    <el-container>
      <!-- 侧边栏 -->
      <el-aside :width="istoggle ? '64px' : '200px' ">
        <!-- 点击收起菜单 -->
        <div class="toggle-button" @click="toggle">|||</div>
        <el-menu
          background-color="#333744"
          text-color="#fff"
          active-text-color="#409eff"
          :unique-opened="true"
          :collapse="istoggle"
          :collapse-transition= "false"
          :router="true"
        >
          <el-submenu
            :index="item.id + ''"
            v-for="item in menulist"
            :key="item.id"
          >
            <template slot="title">
              <i :class="iocn[item.id]"></i>
              <span>{{ item.authName }}</span>
            </template>
            <el-menu-item
              :index=" '' + sunItem.path"
              v-for="sunItem in item.children"
              :key="sunItem.id"
              @click="saveNavState('' + sunItem.path)"
            >
              <template slot="title">
                <i class="el-icon-menu"></i>
                <span>{{ sunItem.authName }}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 右侧内容主题 -->
      <el-main>
        <router-view></router-view> 
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
export default {
  name: 'home',
  data() {
    return {
      // 左侧菜单
      menulist: null,
      iocn: {
        125: 'el-icon-s-custom',
        103: 'el-icon-s-operation',
        101: 'el-icon-s-shop',
        102: 'el-icon-s-claim',
        145: 'el-icon-s-data',
      },
      istoggle: false,
    }
  },
  created() {
    this.getMenu()
  },
  methods: {
    // 获取菜单列表
    async getMenu() {
      const { data: res } = await this.$http.get('menus')
      if (res.meta.status !== 200) {
        return this.$notify.error({
          title: '错误',
          message: res.meta.msg,
        })
      }
      this.menulist = res.data
      // console.log(res)
    },
    // 点击二级菜单 保存
    saveNavState(val){
      // console.log(val);
    },
    // 退出
    logout() {
      sessionStorage.clear()
      this.$router.push('./login')
    },
    // 点击按钮 切换菜单折叠展开 
    toggle(){
      this.istoggle = !this.istoggle
    }
  },
}
</script>
<style lang="less" scoped>
.el-container {
  height: 100%;
  .el-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #000000;
  }
  .el-container {
    .el-menu{
      border-right:none;
    }
    .toggle-button{
      background: #4A5064;
      color: aliceblue;
      font-size: 10px;
      line-height: 24px;
      text-align: center;
      letter-spacing: 0.2em;
      cursor: pointer;
    }
    .el-aside {
      background: #333744;
    }
    .el-main {
      background: #eaedf1;
    }
  }
}
</style>
